#ifdef _WIN32 
#include <windows.h> 
#endif

#include "Taxman.h"

Taxman::Taxman(glm::vec3 _Pos, float _r, float _speed, std::string _Name,
		std::string _modelFName, ModelPool *_mPool, PathFinder *_pathfinder,
		Terrain::Terrain *_ter) :
		Villager(_Pos, _r, _speed, _Name, _modelFName, _mPool, _pathfinder, _ter)
{

	type = OBJ_TAXMAN;
	parentType = OBJ_VILLAGER;

	for (int i = 0; i < 33; i++)
	{
		std::stringstream ss; //create a stringstream
		ss << i + 1; //add number to the stream
		modelID.push_back(mPool->loadModel(modelFName, "_a_00000" + ss.str()));
	}

	costGold = 200;
	money = 0;

	targetBuilding = NULL;

	BuildUnitBar(modelFName + "_char.png");
}

Taxman::~Taxman(void)
{
}

void Taxman::setWork(Building *building)
{
	if (building != NULL)
	{
		targetBuilding = building;

		// set to new job status
		status = STATUS_NEWJOB;
	}
	else
		status = STATUS_READY;
}

void Taxman::doWork()
{
	if (taxingTimer.GetInterval(1000))
	{
		status = STATUS_DONE;
		money = money + targetBuilding->getMoney();
		taxLabel->setCaption("Tax: " + convertInt(money));
	}
}

void Taxman::goWork()
{
	goTo(targetBuilding->get2dPosition());
	status = STATUS_GOWORK;
}

void Taxman::backHome()
{
	GameLogic::resource->setGold(GameLogic::resource->getGold() + money);
	money = 0;
	status = STATUS_READY;
	taxLabel->setCaption("Tax: " + convertInt(money));
}

void Taxman::BuildUnitBar(std::string iconFName)
{
	// main form holding other info and butons
	unitBar = new Gadgets::Form(800, 64);
	unitBar->setPos(glm::vec2(0, 0));

	icon = new Gadgets::Form(64, 64);
	icon->setBackground(iconFName);
	icon->setPos(glm::vec2(5, 0));

	nameLabel = new Gadgets::Label(64, 16);
	nameLabel->setPos(glm::vec2(75, 8));
	nameLabel->setCaption(Name);

	taxLabel = new Gadgets::Label(64, 16);
	taxLabel->setPos(glm::vec2(75, 24));
	taxLabel->setCaption("Tax: " + convertInt(money));

	unitBar->addItem(icon);
	unitBar->addItem(nameLabel);
	unitBar->addItem(taxLabel);
}

